********************************************************************************************
** The Ukrainian Refugee Crisis and the Politics of Public Opinion: Evidence from Hungary **
********************************************************************************************

**********************************
* Replication file, Sections 1-5 *
**********************************

* Authors: Tom Pepinsky; Ádám Reiff; Kriszti Szabó
* Last updated: 22/Jan/2024
*****************************

* The dta-files that are used in sections 1-5 are:
*         omni2204_workfile.dta
*         omni2211_workfile.dta
*         omni2211_EN_withTARKI_final.dta
* These files can be found in the replication package

set scheme white_tableau

************************************************************************
**** Figure 1: Trends in Public Opinion towards Refugees, 2014-2022 ****
************************************************************************

* use "...\omni2211_EN_withTARKI_final.dta", clear
*     //  n=14,162 including all the 14 TARKI waves with mig variables

* Tabulate the migration attitudes
* Results saved in replication Excel "replication_file_Pepinsky_Reiff_Szabo.xlsx", on sheet "Figure 1"

* Apr 2014
tab mig [aweight=weight] if wave==88
* Jan 2016
tab mig [aweight=weight] if wave==99
* Oct 2016
tab mig [aweight=weight] if wave==102
* Jan 2017
tab mig [aweight=weight] if wave==103
* Apr 2022
tab mig [aweight=weight] if wave==121
* Nov 2022
tab mig [aweight=weight] if wave==122

* import excel "...\replication_file_Pepinsky_Reiff_Szabo.xlsx", sheet("Figure 1") firstrow clear

******* FIGURE 1

replace None=None*100
replace Some=Some*100
replace All=All*100
drop DK

xpose, clear
drop in 1
gen t = _n
label define t 1 "No refugees" 2 "Some but not all" 3 "All refugees"
label values t t
label var v1 "4/2014"
label var v2 "1/2016"
label var v3 "10/2016"
label var v4 "1/2017"
label var v5 "4/2022"
label var v6 "11/2022"
graph bar (asis) v1 v2 v3 v4 v5 v6, over(t) blabel(name, size(small) orientation(vertical)) legend(off) title("What do you think? Hungary should allow in...") ylabel(0(10)85) ysize(3) 

graph export Fig1.pdf, as(pdf) replace

**************************************************************
**** Figure 2: Opposition to Refugees by Party, 2014-2022 ****
**************************************************************

* use "...\omni2211_EN_withTARKI_final.dta", clear
*     //  n=14,162 including all the 14 TARKI waves with mig variables

* Tabulate the migration attitudes
* Results saved in replication Excel "replication_file_Pepinsky_Reiff_Szabo.xlsx", on sheet "Figure 2"

* For Fidesz voters and all voters, here are the tabulations
* Note: We collected the data from the original wave files, one by one 
* Some of the variables are in "mig_attitudes_by_socio_econ_variables_2014_17" excel files, in "Mig_attitudes" sheet

* Apr 2014
tab mig [aweight=weight] if fidesz==1 & wave==88
tab mig [aweight=weight] if opp==1 & wave==88
tab mig [aweight=weight] if other==1 & wave==88
tab mig [aweight=weight] if wave==88
* Jan 2016
tab mig [aweight=weight] if fidesz==1 & wave==99
tab mig [aweight=weight] if opp==1 & wave==99
tab mig [aweight=weight] if other==1 & wave==99
tab mig [aweight=weight] if wave==99
* Oct 2016
tab mig [aweight=weight] if fidesz==1 & wave==102
tab mig [aweight=weight] if opp==1 & wave==102
tab mig [aweight=weight] if other==1 & wave==102
tab mig [aweight=weight] if wave==102
* Jan 2017
tab mig [aweight=weight] if fidesz==1 & wave==103
tab mig [aweight=weight] if opp==1 & wave==103
tab mig [aweight=weight] if other==1 & wave==103
tab mig [aweight=weight] if wave==103
* Apr 2022
tab mig [aweight=weight] if fidesz==1 & wave==121
tab mig [aweight=weight] if opp==1 & wave==121
tab mig [aweight=weight] if other==1 & wave==121
tab mig [aweight=weight] if wave==121
* Nov 2022
tab mig [aweight=weight] if fidesz==1 & wave==122
tab mig [aweight=weight] if opp==1 & wave==122
tab mig [aweight=weight] if other==1 & wave==122
tab mig [aweight=weight] if wave==122

* import excel "...\replication_file_Pepinsky_Reiff_Szabo.xlsx", sheet("Figure 2") firstrow clear


*******FIGURE 2

replace Fidesz=Fidesz*100
replace Opposition=Opposition*100
replace Other=Other*100
replace All=All*100

xpose, clear
drop in 1
gen t = _n
label define t 1 "Fidesz" 2 "Opposition" 3 "Other" 4 "All"
label values t t
label var v1 "4/2014"
label var v2 "1/2016"
label var v3 "10/2016"
label var v4 "1/2017"
label var v5 "4/2022"
label var v6 "11/2022"

graph bar (asis) v1 v2 v3 v4 v5 v6, over(t) blabel(name, size(small) orientation(vertical)) legend(off) title("Hungary should let in NO refugees") ylabel(0(10)70)  ysize(3)

graph export Fig2.pdf, as(pdf) replace


************************************************************************
**** Figure 3: Public Opinion towards Refugees by Party, April 2022 ****
************************************************************************

* use "...\omni2204_workfile.dta", clear
*     //  n=1,023, our original survey from April 2022

* Tabulate the migration attitudes
* Results saved in replication Excel "replication_file_Pepinsky_Reiff_Szabo.xlsx", on sheet "Figure 3"

* Fidesz
tab mig [aweight=weight] if partylist==1 & mig<8
* Opposition
tab mig [aweight=weight] if partylist==2 & mig<8
* Radical right
tab mig [aweight=weight] if  partylist==3 & mig<8
* Other 
tab mig [aweight=weight] if partylist>3 & mig<8


******* FIGURE 3

* import excel "...\replication_file_Pepinsky_Reiff_Szabo.xlsx", sheet("Figure 3") firstrow clear

import excel "replication_file_Pepinsky_Reiff_Szabo.xlsx", sheet("Figure 3") firstrow clear

gen T = _n
label define T 1 "Fidesz April" 2 "Opposition April" 3 "Radical Right April" 4 "Other April"
label values T T

* Keep data only for the April 2022 wave
drop if T>4

graph bar (asis) All Some None, over(T) legend(off) blabel(name, size(vsmall)) ylabel(0(10)80) ysize(3) 

graph export Fig3.pdf, as(pdf) replace


***************************************************
**** Table 1: Linear Probability Model Results ****
***************************************************

* use "...\omni2211_EN_withTARKI_final.dta", clear
*     //  n=14,162 including all the 14 TARKI waves with mig variables

* Specification (1): equation without time-varying coefficients
reg nomig fidesz i.wave serv_freq serv_occ female secondary high i.hhmmb student unemp retired inactive age age2 single divorced widowed [aweight=weight] if wave>=88, robust

* Specification (2): equation with time-varying coefficients for Fidesz
reg nomig fidesz5 fidesz6 fidesz7 fidesz8 fidesz9 fidesz10 wave6 wave7 wave8 wave9 wave10 serv_freq serv_occ female secondary high i.hhmmb student unemp retired inactive age age2 single divorced widowed [aweight=weight] if wave>=88, robust


*********************************************************************************
**** Figure 4: Public Opinion towards Refugees by Source Country, April 2022 ****
*********************************************************************************

*******FIGURE 4

*use "omni2204_workfile.dta", clear


replace m_afgpak = . if m_afgpak > 5
replace m_ukrblr = . if m_ukrblr > 5
graph bar (count), over( m_afgpak ) over(m_afgpakNUM) ytitle("") percentages asyvars legend(pos(3) col(1) size(tiny)) name(gr1, replace) legend(rows(1))
graph bar (count), over( m_ukrblr) over(m_ukrblrNUM) ytitle("") percentages asyvars legend(pos(3) col(1)  size(tiny)) name(gr2, replace) 

grc1leg gr1 gr2 , col(1) ycommon ysize(3)

graph export Fig4.pdf, as(pdf) replace



* Replication of Table 2 and Figure 5 come together: they are based on the same regression 
***************************************************
**** Table 2: Difference-indifferences results ****
***************************************************
************************************************************************************
**** Figure 5: Predicted Support for Refugees, Difference-in-Differences Design ****
************************************************************************************

******* FIGURE 5

*use "omni2204_workfile.dta", clear

replace m_afgpak = . if m_afgpak > 5
replace m_ukrblr = . if m_ukrblr > 5
gen Conflict1 = 1
replace Conflict1 = 0 if m_afgpakNUM == 2
gen Conflict2 = 1
replace Conflict2 = 0 if m_ukrblrNUM == 2
gen out1 = m_afgpak
gen out2 = m_ukrblr

keep number out* Conflict*
reshape long out Conflict , i(number) j(Europe)
recode Europe (1=0) (2=1)

summarize out
local sd = r(sd)

* Table 2, OLS specification
areg out i.Europe##i.Conflict, absorb(number) cluster(number)
eststo model1
di 1.1/`sd'
* Figure 5: OLS regression-based margin estimation

margins, at(Europe=(0 1) Conflict=(0 1)) plot(ciopts(lwidth(medium)) title("") xlabel(0 "Not Europe" 1 "Europe") xtitle("") xscale(r(-.3 1.2) noline) ///
	legend(order(1 "No Conflict" 2 "Conflict"))  ysize(3) ///
	text(3.6 1.1 "Ukraine", color(255 127 14)) text(2.6 1.1 "Belarus", color(31 119 180)) ///
	text(2.3 -.13 "Pakistan", color(31 119 180)) text(2.2 -.15 "Afghanistan", color(255 127 14)))

graph export Fig5.pdf, as(pdf) replace



gen outbin = out > 2
* Table 2, Logit specification
clogit outbin i.Europe##i.Conflict, group(number) cluster(number)
eststo model2
* esttab model1 model2 using diffindiff.tex, nobaselevels wide compress replace



**********************************************************************************************
**** Figure 6: Public Opinion towards Refugees by Source Country and by Party, April 2022 ****
**********************************************************************************************

* use "...\omni2204_workfile.dta", clear
*     //  n=1,023, our original survey from April 2022

gen other=partylist>2.5
        // non-Fidesz, non-opposition voters
		
// Re-scale to 0-100
gen ukrblr=m_ukrblr
replace ukrblr=. if m_ukrblr>5.5
gen afgpak=m_afgpak
replace afgpak=. if m_afgpak>5.5
gen ukrblr100=(ukrblr-1)*25
gen afgpak100=(afgpak-1)*25

* Tabulate the migration attitudes
* Results saved in replication Excel "replication_file_Pepinsky_Reiff_Szabo.xlsx", on sheet "Figure 6"

// Ukraine
tabstat ukrblr100 [aweight=weight] if m_ukrblrNUM==1 & m_ukrblr<5.5 & partylist==1
tabstat ukrblr100 [aweight=weight] if m_ukrblrNUM==1 & m_ukrblr<5.5 & partylist==2
tabstat ukrblr100 [aweight=weight] if m_ukrblrNUM==1 & m_ukrblr<5.5 & partylist>2.5
tabstat ukrblr100 [aweight=weight] if m_ukrblrNUM==1 & m_ukrblr<5.5

// Belarus
tabstat ukrblr100 [aweight=weight] if m_ukrblrNUM==2 & m_ukrblr<5.5 & partylist==1
tabstat ukrblr100 [aweight=weight] if m_ukrblrNUM==2 & m_ukrblr<5.5 & partylist==2
tabstat ukrblr100 [aweight=weight] if m_ukrblrNUM==2 & m_ukrblr<5.5 & partylist>2.5
tabstat ukrblr100 [aweight=weight] if m_ukrblrNUM==2 & m_ukrblr<5.5

// Afghanistan
tabstat afgpak100 [aweight=weight] if m_afgpakNUM==1 & m_afgpak<5.5 & partylist==1
tabstat afgpak100 [aweight=weight] if m_afgpakNUM==1 & m_afgpak<5.5 & partylist==2
tabstat afgpak100 [aweight=weight] if m_afgpakNUM==1 & m_afgpak<5.5 & partylist>2.5
tabstat afgpak100 [aweight=weight] if m_afgpakNUM==1 & m_afgpak<5.5

// Pakistan
tabstat afgpak100 [aweight=weight] if m_afgpakNUM==2 & m_afgpak<5.5 & partylist==1
tabstat afgpak100 [aweight=weight] if m_afgpakNUM==2 & m_afgpak<5.5 & partylist==2
tabstat afgpak100 [aweight=weight] if m_afgpakNUM==2 & m_afgpak<5.5 & partylist>2.5
tabstat afgpak100 [aweight=weight] if m_afgpakNUM==2 & m_afgpak<5.5


******* FIGURE 6

import excel "replication_file_Pepinsky_Reiff_Szabo.xlsx", sheet("Figure 6") firstrow clear

* keep only April results

gen T = _n
label define T 1 "Ukraine" 2 "Belarus" 3 "Afghanistan" 4 "Pakistan"
label values T T

* keep only April results
drop if T>4

destring Fideszvoters Oppositionvoters Othervoters Allvoters, replace

graph bar (asis) Fideszvoters Oppositionvoters Othervoters Allvoters, over(T) ///
      legend( label(1 "Fidesz voters") label(2 "Opposition voters") label(3 "Other voters") label(4 "All voters")) legend(pos(bottom) rows(1))
graph export Fig6.pdf, as(pdf) replace


*********************************************************************************************************************************************************************
**** Figure 7: The Relative Support of Fidesz Voters (to non-Fidesz Voters) Towards Refugees from Different Source Countries (Estimated Coefficients), April 2022 ***
*********************************************************************************************************************************************************************

* use "...\omni2204_workfile.dta", clear
*     //  n=1,023, our original survey from April 2022

gen other=partylist>2.5
        // non-Fidesz, non-opposition voters
		
// Re-scale to 0-100
gen ukrblr=m_ukrblr
replace ukrblr=. if m_ukrblr>5.5
gen afgpak=m_afgpak
replace afgpak=. if m_afgpak>5.5
gen ukrblr100=(ukrblr-1)*25
gen afgpak100=(afgpak-1)*25

* Estimating regressions on migration attitudes. Always save the first regression coefficient (on fidesz dummy) to Excel
* Results saved in replication Excel "replication_file_Pepinsky_Reiff_Szabo.xlsx", on sheet "Figure 7"
	  
* Ukraine, panel A
reg ukrblr100 fidesz i.sizecat i.hh roma age age2 single divorced widowed [aweight=weight] if m_ukrblrNUM==1, robust
* Ukraine, panel B
reg ukrblr100 fidesz veryrel slightlyrel uncertainrel i.sizecat i.hh roma age age2 single divorced widowed [aweight=weight] if m_ukrblrNUM==1, robust
* Ukraine, panel C
reg ukrblr100 fidesz serv_freq serv_occ i.sizecat i.hh roma age age2 single divorced widowed [aweight=weight] if m_ukrblrNUM==1, robust
* Ukraine, panel D
reg ukrblr100 fidesz cath prot i.sizecat i.hh roma age age2 single divorced widowed [aweight=weight] if m_ukrblrNUM==1, robust

* Belarus, panel A
reg ukrblr100 fidesz i.sizecat i.hh roma age age2 single divorced widowed [aweight=weight] if m_ukrblrNUM==2, robust
* Belarus, panel B
reg ukrblr100 fidesz veryrel slightlyrel uncertainrel i.sizecat i.hh roma age age2 single divorced widowed [aweight=weight] if m_ukrblrNUM==2, robust
* Belarus, panel C
reg ukrblr100 fidesz serv_freq serv_occ i.sizecat i.hh roma age age2 single divorced widowed [aweight=weight] if m_ukrblrNUM==2, robust
* Belarus, panel D
reg ukrblr100 fidesz cath prot i.sizecat i.hh roma age age2 single divorced widowed [aweight=weight] if m_ukrblrNUM==2, robust
	
* Afghanistan, panel A
reg afgpak100 fidesz i.sizecat ch1 ch2 ch3pl i.hh roma [aweight=weight] if m_afgpakNUM==1, robust
* Afghanistan, panel B
reg afgpak100 fidesz veryrel slightlyrel uncertainrel i.sizecat ch1 ch2 ch3pl i.hh roma [aweight=weight] if m_afgpakNUM==1, robust
* Afghanistan, panel C
reg afgpak100 fidesz serv_freq serv_occ i.sizecat ch1 ch2 ch3pl i.hh roma [aweight=weight] if m_afgpakNUM==1, robust
* Afghanistan, panel D
reg afgpak100 fidesz cath prot i.sizecat ch1 ch2 ch3pl i.hh roma [aweight=weight] if m_afgpakNUM==1, robust

* Pakistan, panel A
reg afgpak100 fidesz i.sizecat ch1 ch2 ch3pl i.hh roma [aweight=weight] if m_afgpakNUM==2, robust
* Pakistan, panel B
reg afgpak100 fidesz veryrel slightlyrel uncertainrel i.sizecat ch1 ch2 ch3pl i.hh roma [aweight=weight] if m_afgpakNUM==2, robust
* Pakistan, panel C
reg afgpak100 fidesz serv_freq serv_occ i.sizecat ch1 ch2 ch3pl i.hh roma [aweight=weight] if m_afgpakNUM==2, robust
* Pakistan, panel D
reg afgpak100 fidesz cath prot i.sizecat ch1 ch2 ch3pl i.hh roma [aweight=weight] if m_afgpakNUM==2, robust

*******FIGURE 7

import excel "replication_file_Pepinsky_Reiff_Szabo.xlsx", sheet("Figure 7") firstrow clear

gen T = _n
label define T 1 "Ukraine" 2 "Belarus" 3 "Afghanistan" 4 "Pakistan"
label values T T

ren EstimatedwithoutreligionA Panel_A
ren withdegreeofreligiosityB Panel_B
ren withserviceparticipationfre Panel_C
ren withreligiousdenominationD Panel_D

la var Panel_A "Panel A"
la var Panel_B "Panel B"
la var Panel_C "Panel C"
la var Panel_D "Panel D"

graph bar (asis) Panel_A Panel_B Panel_C Panel_D, over(T, axis(noline)) 

graph export Fig7.pdf, as(pdf) replace


*****************************************************************************
**** Table 3: Experimental results comparing race and values, April 2022 ****
*****************************************************************************

* use "...\omni2204_workfile.dta", clear
*     //  n=1,023, our original survey from April 2022

// column 1 ("White European")
tab impwhite [aweight=weight] if impwhite<4.5
// column 2 ("Same values")
tab impvalue [aweight=weight] if impvalue<4.5
// column 3 ("Total")
gen white_value=impwhite
replace white_value=impvalue if white_valueNUM==2
tab white_value [aweight=weight] if white_value<4.5

*** independence test: we calculated this in excel as STATA does not allow us to weight chi2 option 
*** see in separate Excel file in "independence_tests.xlsx" excel, on worksheet "Table 3"


******************************************************************
**** Table 4: Race, values, and religion compared, April 2022 ****
******************************************************************

* use "...\omni2204_workfile.dta", clear
*     //  n=1,023, our original survey from April 2022

// Panel A columns 1-5
tab impwhite [aweight=weight] if impwhite<4.5 & impchrist==1
tab impwhite [aweight=weight] if impwhite<4.5 & impchrist==2
tab impwhite [aweight=weight] if impwhite<4.5 & impchrist==3
tab impwhite [aweight=weight] if impwhite<4.5 & impchrist==4
tab impwhite [aweight=weight] if impwhite<4.5 & impchrist<4.5

// Panel B columns 1-5
tab impvalue [aweight=weight] if impvalue<4.5 & impchrist==1
tab impvalue [aweight=weight] if impvalue<4.5 & impchrist==2
tab impvalue [aweight=weight] if impvalue<4.5 & impchrist==3
tab impvalue [aweight=weight] if impvalue<4.5 & impchrist==4
tab impvalue [aweight=weight] if impvalue<4.5 & impchrist<4.5

*** independence test: we calculated this in excel as STATA does not allow us to weight chi2 option 
*** see in separate Excel file in "independence_tests.xlsx" excel, on worksheet "Table 4"


************************************************************************************************
**** Figure 8: The Importance of Immigrants Characteristics and Skills by Party, April 2022 ****
************************************************************************************************

* use "...\omni2204_workfile.dta", clear
*     //  n=1,023, our original survey from April 2022

gen other=partylist>2.5
        // non-Fidesz, non-opposition voters
		
// Re-scale to 0-100
replace impeduc=. if impeduc>4.5
gen impeduc100=(impeduc-1)*100/3
replace impwork=. if impwork>4.5
gen impwork100=(impwork-1)*100/3
replace impwhite=. if impwhite>4.5
gen impwhite100=(impwhite-1)*100/3
replace impvalue=. if impvalue>4.5
gen impvalue100=(impvalue-1)*100/3
replace impchrist=. if impchrist>4.5
gen impchrist100=(impchrist-1)*100/3

* Tabulate the migration attitudes
* Results saved in replication Excel "replication_file_Pepinsky_Reiff_Szabo.xlsx", on sheet "Figure 8"

// Work skills
tabstat impwork100 [aweight=weight] if impwork<4.5 & partylist==1
tabstat impwork100 [aweight=weight] if impwork<4.5 & partylist==2
tabstat impwork100 [aweight=weight] if impwork<4.5 & partylist>2.5
tabstat impwork100 [aweight=weight] if impwork<4.5

// Education
tabstat impeduc100 [aweight=weight] if impeduc<4.5 & partylist==1
tabstat impeduc100 [aweight=weight] if impeduc<4.5 & partylist==2
tabstat impeduc100 [aweight=weight] if impeduc<4.5 & partylist>2.5
tabstat impeduc100 [aweight=weight] if impeduc<4.5

// Same values
tabstat impvalue100 [aweight=weight] if white_valueNUM==2 & impvalue<4.5 & partylist==1
tabstat impvalue100 [aweight=weight] if white_valueNUM==2 & impvalue<4.5 & partylist==2
tabstat impvalue100 [aweight=weight] if white_valueNUM==2 & impvalue<4.5 & partylist>2.5
tabstat impvalue100 [aweight=weight] if white_valueNUM==2 & impvalue<4.5

// White
tabstat impwhite100 [aweight=weight] if white_valueNUM==1 & impwhite<4.5 & partylist==1
tabstat impwhite100 [aweight=weight] if white_valueNUM==1 & impwhite<4.5 & partylist==2
tabstat impwhite100 [aweight=weight] if white_valueNUM==1 & impwhite<4.5 & partylist>2.5
tabstat impwhite100 [aweight=weight] if white_valueNUM==1 & impwhite<4.5

// Christian
tabstat impchrist100 [aweight=weight] if impchrist<4.5 & partylist==1
tabstat impchrist100 [aweight=weight] if impchrist<4.5 & partylist==2
tabstat impchrist100 [aweight=weight] if impchrist<4.5 & partylist>2.5
tabstat impchrist100 [aweight=weight] if impchrist<4.5


*******FIGURE 8

import excel "replication_file_Pepinsky_Reiff_Szabo.xlsx", sheet("Figure 8") firstrow clear

gen T = _n
label define T 1 "Work skills" 2 "Education" 3 "Same values" 4 "White" 5 "Christian" 
label values T T

graph bar (asis) Fideszvotersapr Oppositionvotersapr Othervotersapr Allvotersapr, over(T) ///
	legend( label(1 "Fidesz") label(2 "Opposition") label(3 "Other") label(4 "All") pos(bottom) rows(1))

graph export Fig8.pdf, as(pdf) replace


***********************************************************************************************************
**** Figure 9: The Importance of Different Ethnic Background of Immigrants by Partisanship, April 2022 ****
***********************************************************************************************************

* use "...\omni2204_workfile.dta", clear
*     //  n=1,023, our original survey from April 2022

gen other=partylist>2.5
        // non-Fidesz, non-opposition voters
		
// Re-scale to 0-100
replace ethnichun=. if ethnichun>4.5
gen ethnichun100=(ethnichun-1)*100/3
replace german=. if german>4.5
gen german100=(german-1)*100/3
replace arabic=. if arabic>4.5
gen arabic100=(arabic-1)*100/3
replace russian=. if  russian>4.5
gen russian100=(russian-1)*100/3
replace chinese=. if  chinese>4.5
gen chinese100=(chinese-1)*100/3
replace piresian=. if piresian>4.5
gen piresian100=(piresian-1)*100/3
replace piresistan=. if piresistan>4.5
gen piresistan100=(piresistan-1)*100/3

* Tabulate the migration attitudes
* Results saved in replication Excel "replication_file_Pepinsky_Reiff_Szabo.xlsx", on sheet "Figure 9"

// Ethnic Hungarians
tabstat ethnichun100 [aweight=weight] if ethnichun<4.5 & partylist==1
tabstat ethnichun100 [aweight=weight] if ethnichun<4.5 & partylist==2
tabstat ethnichun100 [aweight=weight] if ethnichun<4.5 & partylist>2.5
tabstat ethnichun100 [aweight=weight] if ethnichun<4.5

// Germans
tabstat german100 [aweight=weight] if german<4.5 & partylist==1
tabstat german100 [aweight=weight] if german<4.5 & partylist==2
tabstat german100 [aweight=weight] if german<4.5 & partylist>2.5
tabstat german100 [aweight=weight] if german<4.5

// Russians
tabstat russian100 [aweight=weight] if russian<4.5 & partylist==1
tabstat russian100 [aweight=weight] if russian<4.5 & partylist==2
tabstat russian100 [aweight=weight] if russian<4.5 & partylist>2.5
tabstat russian100 [aweight=weight] if russian<4.5

// Chinese
tabstat chinese100 [aweight=weight] if chinese<4.5 & partylist==1
tabstat chinese100 [aweight=weight] if chinese<4.5 & partylist==2
tabstat chinese100 [aweight=weight] if chinese<4.5 & partylist>2.5
tabstat chinese100 [aweight=weight] if chinese<4.5

// Arabic
tabstat arabic100 [aweight=weight] if arabic<4.5 & partylist==1
tabstat arabic100 [aweight=weight] if arabic<4.5 & partylist==2
tabstat arabic100 [aweight=weight] if arabic<4.5 & partylist>2.5
tabstat arabic100 [aweight=weight] if arabic<4.5

// Piresian
tabstat piresian100 [aweight=weight] if pires_istanNUM==1 & piresian<4.5 & partylist==1
tabstat piresian100 [aweight=weight] if pires_istanNUM==1 & piresian<4.5 & partylist==2
tabstat piresian100 [aweight=weight] if pires_istanNUM==1 & piresian<4.5 & partylist>2.5
tabstat piresian100 [aweight=weight] if pires_istanNUM==1 & piresian<4.5

// Piresistani
tabstat piresistan100 [aweight=weight] if pires_istanNUM==2 & piresistan<4.5 & partylist==1
tabstat piresistan100 [aweight=weight] if pires_istanNUM==2 & piresistan<4.5 & partylist==2
tabstat piresistan100 [aweight=weight] if pires_istanNUM==2 & piresistan<4.5 & partylist>2.5
tabstat piresistan100 [aweight=weight] if pires_istanNUM==2 & piresistan<4.5


******* FIGURE 9

import excel "replication_file_Pepinsky_Reiff_Szabo.xlsx", sheet("Figure 9") firstrow clear

gen T = _n
label define T 1 "Hungarian" 2 "German" 3 "Russian" 4 "Chinese" 5 "Arab" 6 "Piresian" 7 "Piresistanian"
label values T T

graph bar (asis) Fideszvotersapr Oppositionvotersapr Othervotersapr Allvotersapr , over(T) ///
     legend( label(1 "Fidesz voters") label(2 "Opposition voters") label(3 "Other voters") label(4 "All voters") pos(bottom) rows(1))

graph export Fig9.pdf, as(pdf) replace

	
***************************************************************************************************
**** Table 5: The Role of Refugee Gender and Source Country on Public Opinion towards Refugees ****
***************************************************************************************************

* use "...\omni2211_workfile.dta", clear
*     //  n=1,000, our original survey from November 2022

replace roma=0 if roma==.

gen m_afgukrGENDER100=(m_afgukrGENDER-1)*25
replace m_afgukrGENDER100=. if m_afgukrGENDER100>100.5

gen female1=(male_femaleNUM==2)
gen ukraine1=(afg_ukrNUM==2)

* Column 1: without religiosity, without interaction
reg m_afgukrGENDER100 female1 ukraine1 fidesz female secondary high i.sizecat i.hh roma age age2 single divorced widowed [aweight=weight], robust
* Column 2: without religiosity, with interaction
reg m_afgukrGENDER100 i.female1##i.ukraine1 fidesz female secondary high i.sizecat i.hh roma age age2 single divorced widowed [aweight=weight], robust

* Column 3: with religious degree, without interaction
reg m_afgukrGENDER100 female1 ukraine1 fidesz veryrel slightlyrel female secondary high i.sizecat i.hh roma age age2 single divorced widowed [aweight=weight], robust
* Column 4: with religious degree, with interaction
reg m_afgukrGENDER100 i.female1##i.ukraine1 fidesz veryrel slightlyrel female secondary high i.sizecat i.hh roma age age2 single divorced widowed [aweight=weight], robust

* Column 5: with service participation frequency, without interaction
reg m_afgukrGENDER100 female1 ukraine1 fidesz serv_freq serv_occ female secondary high i.sizecat i.hh roma age age2 single divorced widowed [aweight=weight], robust
* Column 6: with service participation frequency, with interaction
reg m_afgukrGENDER100 i.female1##i.ukraine1 fidesz serv_freq serv_occ female secondary high i.sizecat i.hh roma age age2 single divorced widowed [aweight=weight], robust


**************************************************************************************************
**** Figure 10: Predicted Support for Refugees by Source Country and by Gender, November 2022 ****
**************************************************************************************************

*******FIGURE 10

use "omni2211_workfile.dta", clear
*     //  n=1,000, our original survey from November 2022

replace roma=0 if roma==.

gen m_afgukrGENDER100=(m_afgukrGENDER-1)*25
replace m_afgukrGENDER100=. if m_afgukrGENDER100>100.5

gen female1=(male_femaleNUM==2)
gen ukraine1=(afg_ukrNUM==2)

* Specification in column 5 of Table 10: margins are calculated for this one
reg m_afgukrGENDER100 female1 ukraine1 fidesz serv_freq serv_occ female secondary high i.sizecat i.hh roma age age2 single divorced widowed [aweight=weight], robust

margins, at(female1=(0 1) ukraine1=(0 1)) plot(ciopts(lwidth(medium)) xlabel(0 "Male" 1 "Female and children") xtitle("") xscale(r(-.05 1.1) noline) ///
	legend(off)  ysize(3) title("") text(59 .5 "Ukraine", color(255 127 14)) text(42 .5 "Afghanistan", color(31 119 180)))

graph export Fig10.pdf, as(pdf) replace


*****************************************************************************************
**** Figure 11: Opposition to Refugees by Religious Service Participation, 2011-2022 ****
*****************************************************************************************

* use "...\omni2211_EN_withTARKI_final.dta", clear
*     //  n=14,162 including all the 14 TARKI waves with mig variables

* Tabulate the migration attitudes
* Results saved in replication Excel "replication_file_Pepinsky_Reiff_Szabo.xlsx", on sheet "Figure 11"

replace nomig=0 if mig==8 | mig==9 | mig==88 | mig==99

* April 2011
tab nomig [aweight=weight] if wave==56 & serv_never==1
tab nomig [aweight=weight] if wave==56 & serv_occ==1
tab nomig [aweight=weight] if wave==56 & serv_freq==1
tab nomig [aweight=weight] if wave==56
* May 2011
tab nomig [aweight=weight] if wave==57 & serv_never==1
tab nomig [aweight=weight] if wave==57 & serv_occ==1
tab nomig [aweight=weight] if wave==57 & serv_freq==1
tab nomig [aweight=weight] if wave==57
* June 2011
tab nomig [aweight=weight] if wave==58 & serv_never==1
tab nomig [aweight=weight] if wave==58 & serv_occ==1
tab nomig [aweight=weight] if wave==58 & serv_freq==1
tab nomig [aweight=weight] if wave==58
* March 2012
tab nomig [aweight=weight] if wave==66 & serv_never==1
tab nomig [aweight=weight] if wave==66 & serv_occ==1
tab nomig [aweight=weight] if wave==66 & serv_freq==1
tab nomig [aweight=weight] if wave==66
* April 2014
tab nomig [aweight=weight] if wave==88 & serv_never==1
tab nomig [aweight=weight] if wave==88 & serv_occ==1
tab nomig [aweight=weight] if wave==88 & serv_freq==1
tab nomig [aweight=weight] if wave==88
* January 2016
tab nomig [aweight=weight] if wave==99 & serv_never==1
tab nomig [aweight=weight] if wave==99 & serv_occ==1
tab nomig [aweight=weight] if wave==99 & serv_freq==1
tab nomig [aweight=weight] if wave==99
* October 2016
tab nomig [aweight=weight] if wave==102 & serv_never==1
tab nomig [aweight=weight] if wave==102 & serv_occ==1
tab nomig [aweight=weight] if wave==102 & serv_freq==1
tab nomig [aweight=weight] if wave==102
* January 2017
tab nomig [aweight=weight] if wave==103 & serv_never==1
tab nomig [aweight=weight] if wave==103 & serv_occ==1
tab nomig [aweight=weight] if wave==103 & serv_freq==1
tab nomig [aweight=weight] if wave==103
* April 2022
tab nomig [aweight=weight] if wave==121 & serv_never==1
tab nomig [aweight=weight] if wave==121 & serv_occ==1
tab nomig [aweight=weight] if wave==121 & serv_freq==1
tab nomig [aweight=weight] if wave==121
* November 2022
tab nomig [aweight=weight] if wave==122 & serv_never==1
tab nomig [aweight=weight] if wave==122 & serv_occ==1
tab nomig [aweight=weight] if wave==122 & serv_freq==1
tab nomig [aweight=weight] if wave==122

******* FIGURE 11

* import excel "...\replication_file_Pepinsky_Reiff_Szabo.xlsx", sheet("Figure 11") firstrow clear

gen T = _n
label define T 1 "Apr 2011" 2 "May 2011" 3 "Jun 2011" 4 "Mar 2012" 5 "Apr 2014" 6 "Jan 2016" 7 "Oct 2016" 8 "Jan 2017" 9 "Apr 2022" 10 "Nov 2022"
label values T T

graph bar (asis) Never Occasionally Frequently, over(T, lab(angle(45))) title("Hungary should let in NO refugees")

graph export Fig11.pdf, as(pdf) replace


*****************************************************************************************
**** Figure 12: Opposition to Refugees by Religious Service Participation, 2011-2022 ****
*****************************************************************************************


******* FIGURE 12

use "omni2211_EN_withTARKI_final.dta", clear

* time-varying coeffs for serv_freq
gen serv_freq1=serv_freq*(wave==56)
gen serv_freq2=serv_freq*(wave==57)
gen serv_freq3=serv_freq*(wave==58)
gen serv_freq4=serv_freq*(wave==66)
gen serv_freq5=serv_freq*(wave==88)
gen serv_freq6=serv_freq*(wave==99)
gen serv_freq7=serv_freq*(wave==102)
gen serv_freq8=serv_freq*(wave==103)
gen serv_freq9=serv_freq*(wave==121)
gen serv_freq10=serv_freq*(wave==122)
gen serv_freqprior=serv_freq*(wave<89)

* time-varying coeffs for serv_occ
gen serv_occ1=serv_occ*(wave==56)
gen serv_occ2=serv_occ*(wave==57)
gen serv_occ3=serv_occ*(wave==58)
gen serv_occ4=serv_occ*(wave==66)
gen serv_occ5=serv_occ*(wave==88)
gen serv_occ6=serv_occ*(wave==99)
gen serv_occ7=serv_occ*(wave==102)
gen serv_occ8=serv_occ*(wave==103)
gen serv_occ9=serv_occ*(wave==121)
gen serv_occ10=serv_occ*(wave==122)
gen serv_occprior=serv_occ*(wave<89)

* Visualising the margins
gen relig_intense=0
replace relig_intense=1 if serv_never==1
replace relig_intense=2 if serv_occ==1
replace relig_intense=3 if serv_freq==1
replace relig_intense=. if serv_freq==. 

gen wave_cat=0
replace wave_cat=1 if wave==56
replace wave_cat=2 if wave==57
replace wave_cat=3 if wave==58
replace wave_cat=4 if wave==66
replace wave_cat=5 if wave==88
replace wave_cat=6 if wave==99
replace wave_cat=7 if wave==102
replace wave_cat=8 if wave==103
replace wave_cat=9 if wave==121
replace wave_cat=10 if wave==122

*labelling the main variables 
label define T 1 "Apr 2011" 2 "May 2011" 3 "Jun 2011" 4 "Mar 2012" 5 "Apr 2014" 6 "Jan 2016" 7 "Oct 2016" 8 "Jan 2017" 9 "Apr 2022" 10 "Nov 2022"
label values wave_cat T

label define t 1 "Never" 2 "Occasionally" 3 "Frequently"
label values relig_intense t

reg nomig fidesz i.relig_intense##i.wave_cat female secondary high i.hhmmb student unemp retired inactive age age2 single divorced widowed [aweight=weight] if wave>=56, robust
margins, at(relig_intense=(1 3) wave_cat=(1(1)10)) plot(__swapxp recastci(rarea))
margins, at(relig_intense=(1 3) wave_cat=(1(1)10)) 
marginsplot, __swapxp recastci(rarea) ci1opts(color(%1) fcolor(%60) ) ci2opts(color(%1) fcolor(%60)) xtitle("") ///
	text(.2 4 "Frequently", color(255 127 14)) text(.55 4 "Never", color(31 119 180)) legend(off) title("") xscale(r(.9 10.1))
graph export Fig12.pdf, as(pdf) replace

